class_name EnemyTemplate

extends CharacterBody2D

enum Direction {
	LEFT = -1,
	RIGHT = +1,
}

# 初始方向
@export var direction = Direction.LEFT:
	set(value):
		direction = value
		if not is_node_ready():
			await ready
		graphics.scale.x = -direction

@export var max_speed = 100.0
@export var acceleration = 2000.0

# 重力加速度
var defualt_gravity := ProjectSettings.get("physics/2d/default_gravity") as float

@onready var graphics: Node2D = $Graphics
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var state_machine: StateMachine = $StateMachine

func _ready() -> void:
	add_to_group("enemies")
	
func move(speed: float, delta: float) -> void:
	velocity.x = move_toward(velocity.x, speed * direction, acceleration * delta)
	velocity.y += defualt_gravity * delta
	move_and_slide()

# 统一处理死亡逻辑
func die() -> void:
	queue_free()
